#!/bin/bash
# Run args as command, but run cpuprofile and then pprof to capture test cpuprofile output
if [ -n "${BENT_PGO}" ] ; then
    pf="${BENT_PGO}/${BENT_BENCH}.prof"
    mkdir -p ${BENT_PGO}
else
    pf="${BENT_PROFILES}/${BENT_BINARY}_${BENT_I}.prof"
    mkdir -p ${BENT_PROFILES}
fi
"$@" -test.cpuprofile="$pf"
echo cpuprofile in "$pf"
if [[ x`which pprof` == x"" ]] ; then
    go tool pprof -text -flat -nodecount=20 "$pf"
else
    pprof -text -flat -nodecount=20 "$pf"
fi
